/*
 * This file (AxBoolParameter.java) is protected by the GNU GPL licence (v2). 
 * Please read the license.txt attached for further informations. 
 * 
 */

package artx.parameters;

import artx.utils.AxLog;

/**
 * Boolean parameter class.
 * 
 * @author Xavier Gouchet
 * 
 */
public class AxBoolParameter extends AxParameter {

	/** Boolean value of the parameter */
	protected boolean boolValue;

	/**
	 * Standard constructor.
	 * 
	 * @param name
	 *            name of the parameter
	 */
	public AxBoolParameter(String name) {
		super(name, "bool");
	}

	/**
	 * Standard constructor.
	 * 
	 * @param name
	 *            name of the parameter
	 * @param reset
	 *            default value of the parameter
	 */
	public AxBoolParameter(String name, String reset) {
		super(name, "bool", reset);
	}

	/**
	 * Get the boolean state of the parameter.
	 * 
	 * @return boolean value of the parameter
	 */
	public boolean GetValue() {
		return this.boolValue;
	}

	/**
	 * @see artx.parameters.AxParameter#UpdateValue()
	 */
	public boolean UpdateValue() {
		if ((this.strValue == null) || (this.strValue.isEmpty())) {
			this.boolValue = false;
			return true;
		} else {
			if ((this.strValue.equals("true")) || this.strValue.equals("1")
					|| this.strValue.equals("yes") || this.strValue.equals("y")
					|| this.strValue.equals("t") || this.strValue.equals("on")) {
				this.boolValue = true;
				return true;
			} else {
				if ((this.strValue.equals("false"))
						|| this.strValue.equals("0")
						|| this.strValue.equals("no")
						|| this.strValue.equals("n")
						|| this.strValue.equals("f")
						|| this.strValue.equals("off")) {
					this.boolValue = false;
					return true;
				} else {
					AxLog.Error("Can't convert parameter " + this.NAME
							+ "'s value \"" + this.strValue + "\" to bool");
					return false;
				}
			}
		}
	}

}
